package logic.moves;

import java.io.Serializable;

import logic.Country;
import logic.Player;

public class AddSoldierMove implements GameMove, Serializable  {

	private static final long serialVersionUID = 1L;

	public static final String move_type = "ADDSOLDIERMOVE";
	
	private boolean hasMoved = false;
	private Player player;
	private Country country;
	private int amount;
	
	/**
	 * @param player
	 * @param country
	 * @param amount
	 */
	public AddSoldierMove(Player player, Country country, int amount) {
		this.player = player;
		this.country = country;
		this.amount = amount;
	}

	public String getType() {
		return move_type;
	}

	public boolean hasMoved() {
		return hasMoved;
	}

	public boolean makeMove() {
		if(this.hasMoved){
			return false;
		} else if(this.country.getOwner() != this.player){
			System.err.println("You are not the owner of " + this.country + " so you can't add soldiers on it");
			return false;
		} else if(this.player.getSoldiers() < this.amount){
			System.err.println("You have only " + this.player.getSoldiers() + " unplaced soldiers to use");
			return false;
		} else {
			this.hasMoved = true;
			this.player.placeSoldiers(country, amount);
			return true;
		}

	}

	public void printDoMove() {
		System.out.println(this.player.getPlayerName() + " added " + this.amount + " soldiers on " + this.country.getName());
	}

	public void printUndoMove() {
		System.out.println(this.player.getPlayerName() + " un-added " + this.amount + " soldiers on " + this.country.getName());
	}

	public void restore() {
		if(!this.hasMoved){
			return;
		} else {
			this.player.unplaceSoldiers(country, amount);
			this.hasMoved = false;
		}
	}


	public void printShortDescription() {
		System.out.println(this.player.getPlayerName() + " added " + this.amount + " soldiers on " + this.country.getName());
	}

	public String getBriefDo() {
		return this.player.getPlayerName() + " added " + this.amount + " soldiers on " + this.country.getName();
	}

	public String getBriefUndo() {
		return this.player.getPlayerName() + " un-added " + this.amount + " soldiers on " + this.country.getName();
	}
	
	public Country getCountry() {
		return country;
	}
	

}
